package com.drg.center.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.drg.center.entity.enums.ResTypeEnum;
import com.drg.center.mapper.SysResourcesMapper;
import com.guaike.core.mybatis.plugins.BaseDAO;
import com.drg.center.entity.SysResourcesPO;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @Author: zhangxilin
 * @Date: 2023/10/30
 */
@Repository
public class SysResourcesDAO extends BaseDAO<SysResourcesMapper, SysResourcesPO> {

    public List<SysResourcesPO> findList(String sysCode, Boolean isExcludeBtn){
        LambdaQueryWrapper<SysResourcesPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysResourcesPO::getSysCode,sysCode);
        if(isExcludeBtn){
            queryWrapper.ne(SysResourcesPO::getResType, ResTypeEnum.button.getCode());
        }
        queryWrapper.orderByAsc(SysResourcesPO::getSortIndex);
        return getBaseMapper().selectList(queryWrapper);
    }


    public List<SysResourcesPO> findSubList(String traceIds){
        LambdaQueryWrapper<SysResourcesPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.likeRight(SysResourcesPO::getTraceIds, traceIds);
        lambdaQueryWrapper.orderByAsc(SysResourcesPO::getTraceIds);
        return getBaseMapper().selectList(lambdaQueryWrapper);
    }


    public List<SysResourcesPO> findBtnUriList(List<Long> ids){
        LambdaQueryWrapper<SysResourcesPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.in(SysResourcesPO::getId, ids);
        lambdaQueryWrapper.eq(SysResourcesPO::getResType, ResTypeEnum.button.getCode());
        lambdaQueryWrapper.isNotNull(SysResourcesPO::getUri);
        return getBaseMapper().selectList(lambdaQueryWrapper);
    }

    public List<SysResourcesPO> findCondition(String sysCode,List<Long> ids, ResTypeEnum resTypeEnum){
        LambdaQueryWrapper<SysResourcesPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(SysResourcesPO::getSysCode,sysCode);
        if(!CollectionUtils.isEmpty(ids)){
            lambdaQueryWrapper.in(SysResourcesPO::getId,ids);
        }
        if(resTypeEnum !=null){
            lambdaQueryWrapper.eq(SysResourcesPO::getResType, resTypeEnum.getCode());
        }
        lambdaQueryWrapper.orderByAsc(SysResourcesPO::getSortIndex);
        return getBaseMapper().selectList(lambdaQueryWrapper);
    }


}
